#include <stdio.h>
int main()
{
    int n,a[100],i,j,MinN,t;
    while (scanf("%d",&n)!=EOF)
    {
        if (n==0)break;
        for (i=0;i<n;i++)scanf("%d",&a[i]);
        MinN=60000;
        for (i=0;i<n;i++)if (MinN>a[i]){t=i;MinN=a[i];}
        printf("%d ",MinN);
        for (i=1;i<n-1;i++)
        {
            if (t==i)printf("%d ",a[0]);
            else printf("%d ",a[i]);
        }
                  if (t==n-1)printf("%d",a[0]);
                  else printf("%d",a[n-1]);
        printf("\n");
    }
    return 0;
}
